#include <HardwareSerial.h>
#include "Commander.h"

char character;

Commander::Commander() : command("") {
}

String const *Commander::readRequest() {
    command = "";

    while (Serial.available() > 0) {
        character = (char) Serial.read();
        if (character == '\n') {
            break;
        }
        command.concat(character);
    }

    if (command.length() == 0) {
        return NULL;
    }
    command.trim();
    return &command;
}

void Commander::writeResponse(error_t error) {
    Serial.print("ERR");
    Serial.println(error);
}

void Commander::writeResponse(String const &response) {
    Serial.println(response);
}
